{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Parameter inference using neural networks\n",
    "\n",
    "Tom Charnock\n",
    "\n",
    "Institut d'Astrophysique de Paris\n",
    "<br><br><br>\n",
    "\n",
    "<div class=\"row\">\n",
    "    <div style=\"float: left; width: 20%; padding-right: 70px; padding-top:35px\">\n",
    "        <img src=\"../figures/SU.png\" alt=\"Sorbonne Université\" style=\"width:80%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 0px;\">\n",
    "        <img src=\"../figures/ANR.png\" alt=\"ANR\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/IAP.png\" alt=\"IAP\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/CNRS.png\" alt=\"CNRS\" style=\"width:30%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/Aquila.png\" alt=\"Aquila\" style=\"width:60%;\"/>\n",
    "    </div>\n",
    "</div> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## What is a neural network?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:50%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/neural_network_t.svg\">\n",
    "<br>\n",
    "<center>\n",
    "$$\\mathbb{NN}(\\boldsymbol{w},\\boldsymbol{\\alpha}) : {\\bf d}\\rightarrow\\boldsymbol{\\tau}$$<br><br>\n",
    "An approximation to a model, $\\mathcal{M} : {\\bf d}\\rightarrow{\\bf t}$\n",
    "</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## What are they used for?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Emulation (generative networks)\n",
    "<br>\n",
    "<div style=\"float:left;width:50%\">\n",
    "    <br><br><br><br>\n",
    "<center>$\\mathbb{NN}(\\boldsymbol{w},\\boldsymbol{\\alpha}) : {\\bf z}\\to{\\bf t}$<br><br>${\\bf t}\\in\\mathcal{P}({\\bf t}|{\\bf z})\\simeq{\\bf d}\\in\\mathcal{P}({\\bf d})$\n",
    "<center>\n",
    "</div>\n",
    "<div style=\"float:left;width:50%\">\n",
    "    <br>\n",
    "    <img style=\"max-width:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/density_field.svg\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Classification\n",
    "<br>\n",
    "<div style=\"float:left;width:55%\">\n",
    "    <br><br><br>\n",
    "<center>\n",
    "    $\\mathbb{NN}(\\boldsymbol{w},\\boldsymbol{\\alpha}) : {\\bf d}\\to{\\bf t}$<br><br>${\\bf t}\\in\\mathcal{P}({\\bf t})\\simeq{\\bf d}\\in\\mathcal{P}(\\textrm{type}|{\\bf d})$\n",
    "</center>\n",
    "</div>\n",
    "    <div style=\"float:left;width:45%\">\n",
    "    <img style=\"max-width:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/classification.svg\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Extremely popular for cosmological parameter estimation\n",
    "<br>\n",
    "<div style=\"float:left;width:40%\">\n",
    "    <img style=\"max-height:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/PI_list.png\">\n",
    "</div>\n",
    "<div style=\"float:left;width:60%\">\n",
    "    <img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/PI_plot.png\"><br>\n",
    "<center>$\\mathcal{M} : \\boldsymbol{\\theta}\\to{\\bf d}$<br>$\\overset{~}{\\mathbb{NN}}(\\boldsymbol{w},\\boldsymbol{\\alpha}) : {\\bf d}\\to\\hat{\\boldsymbol{\\theta}}$\n",
    "</center>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Unfortunately..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### None of these work in a scientifically rigourous way!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# To see why we need to do some stats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### A physical model $\\small\\mathcal{M} : \\boldsymbol{\\theta}\\to{\\bf d}$\n",
    "The generator of data $({\\bf d})$ with parameters $(\\boldsymbol{\\theta})$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:100%;max-height:60%;width:1000px;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/physical_model.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### The likelihood and the posterior"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div style=\"float:left;width:60%\">\n",
    "    <br>\n",
    "    <img style=\"max-width:90%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/likelihood_posterior.svg\">\n",
    "</div>\n",
    "<div style=\"float:left;width:40%\">\n",
    "    <b>Likelihood</b> $\\mathcal{L}({\\bf d}|\\boldsymbol{\\theta}^*)$<br>What is the probability that the model generates data ${\\bf d}$ given a set of model parameters $\\boldsymbol{\\theta}^*$?<br><br>\n",
    "    <b>Posterior</b> $\\mathcal{P}(\\boldsymbol{\\theta}|{\\bf d}^*)$<br>What is the probability that model parameters $\\boldsymbol{\\theta}$ generate the data ${\\bf d}^*$?\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Maximum likelihood estimates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div style=\"float:left;width:40%\">\n",
    "    <br>\n",
    "        <img style=\"max-width:90%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/mle.gif\">\n",
    "</div>\n",
    "<div style=\"float:left;width:60%\">\n",
    "    Which value of the model parameters $\\boldsymbol{\\theta}$ is most likely to generate the observed population of data $\\{{\\bf d}\\}$?\n",
    "    <br>\n",
    "    <img style=\"max-width:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/MLE.svg\">\n",
    "    $$\\mathcal{L}(\\{{\\bf d}\\}|\\boldsymbol{\\theta}_\\textsf{MLE})=\\underset{\\boldsymbol{\\theta}\\in\\boldsymbol{\\Theta}}{\\textsf{Sup}}~\\mathcal{L}(\\{{\\bf d}\\}|\\boldsymbol{\\theta})$$\n",
    "</div>   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Training a network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:90%;max-height:50%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/Flat_likelihood_t.svg\">\n",
    "<div style=\"float:left;width:55%\"><br>\n",
    "    $\\mathcal{M} : {\\bf d} \\to {\\bf t}$ <b> approximator</b><br>\n",
    "    <br>\n",
    "    $$\\mathbb{NN}(\\boldsymbol{w}, \\boldsymbol{\\alpha}) : {\\bf d}\\to\\boldsymbol{\\tau}$$\n",
    "    <br>\n",
    "    <b>Cost function and likelihood</b>\n",
    "    $$\\boldsymbol{\\Lambda}({\\bf t}, \\boldsymbol{\\tau}) = -\\ln\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w}^*,\\boldsymbol{\\alpha}^*)$$\n",
    "</div>\n",
    "<div style=\"float:left;width:45%\">\n",
    "    <center>\n",
    "    $\\boldsymbol{\\Lambda}({\\bf t},\\boldsymbol{\\tau})$<br>smooth and convex<br><br>\n",
    "    $\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w},\\boldsymbol{\\alpha})$<br>complex, discrete and possibly non-convex in $\\boldsymbol{w}$ and $\\boldsymbol{\\alpha}$\n",
    "    </center>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Optimising a network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Given a set of training data $\\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1,n_\\textrm{train}]\\}$ what is the maximum likelihood estimate of the weights?<br>\n",
    "\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/mle_net.gif\">\n",
    "\n",
    "$$\\small\\boldsymbol{w}^\\textrm{MLE}=\\underset{\\boldsymbol{w}}{\\textrm{argmax}}\\left[\\mathcal{L}(\\{{\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\}|\\{{\\bf d}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\}, \\boldsymbol{w}, \\boldsymbol{\\alpha}^*)\\right]$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Where the problem starts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### The posterior predictive density $\\mathcal{P}({\\bf t}|{\\bf d})$\n",
    "\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/posterior_predictive_t.svg\">\n",
    "\n",
    "$$\\mathcal{P}({\\bf t}|{\\bf d})= \\int d\\boldsymbol{w}\\boldsymbol{\\alpha}\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w},\\boldsymbol{\\alpha})p(\\boldsymbol{w},\\boldsymbol{\\alpha})$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Failure of traditional networks\n",
    "<br>\n",
    "<center>\n",
    "$p(\\boldsymbol{w}, \\boldsymbol{\\alpha})=\\delta(\\boldsymbol{w}-\\boldsymbol{w}^\\textrm{local MLE}, \\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)$<br><br>\n",
    "$\\mathcal{P}({\\bf t}|{\\bf d})  =\\delta(\\boldsymbol{\\tau})$\n",
    "</center>\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/nn_b_t.gif\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Variational inference\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/VB_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\tiny\\mathcal{P}({\\bf t}|{\\bf d})=\\int d\\boldsymbol{w}d\\boldsymbol{v}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w},\\boldsymbol{\\alpha})\\mathcal{Q}(\\boldsymbol{w}|\\boldsymbol{v}, \\boldsymbol{\\alpha}, \\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\})p(\\boldsymbol{v},\\boldsymbol{\\alpha})$$\n",
    "<br>\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/vi_b_t.gif\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Still depends on training the complex likelihood surface and choice of variational distribution\n",
    "<br>\n",
    "<img style=\"max-width:110%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/wrong_variational.svg\">\n",
    "$$\\begin{align*}\\tiny\n",
    "\\mathcal{P}({\\bf t}|{\\bf d})&=\\tiny\\int d\\boldsymbol{w}d\\boldsymbol{v}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w},\\boldsymbol{\\alpha})\\mathcal{Q}(\\boldsymbol{w}|\\boldsymbol{v}, \\boldsymbol{\\alpha}, \\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\})\\\\\n",
    "&\\tiny\\phantom{=hello}\\times\\delta(\\boldsymbol{v}-\\boldsymbol{v}^\\textrm{local MLE}, \\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)\\\\\n",
    "&\\tiny=\\int d\\boldsymbol{w}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{w}, \\boldsymbol{\\alpha}^*)\\mathcal{Q}(\\boldsymbol{w}|\\boldsymbol{v}^\\textrm{local MLE}, \\boldsymbol{\\alpha}^*, \\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\}).\n",
    "\\end{align*}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Bayesian neural networks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/Bayes_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\begin{align*}\n",
    "\\tiny    \\mathcal{P}({\\bf t}|{\\bf d}) =&\\tiny~\\int d\\boldsymbol{w}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d}, \\boldsymbol{w}, \\boldsymbol{\\alpha})\\mathcal{P}(\\boldsymbol{w},\\boldsymbol{\\alpha}|\\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\})\\\\\n",
    "  \\tiny  =&\\tiny~\\int d\\boldsymbol{w}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d}, \\boldsymbol{w}, \\boldsymbol{\\alpha})\\prod_i^{n_\\textrm{train}}\\mathcal{L}({\\bf t}^\\textrm{train}_i|{\\bf d}^\\textrm{train}_i,\\boldsymbol{w},\\boldsymbol{\\alpha})p(\\boldsymbol{w},\\boldsymbol{\\alpha}).\n",
    "\\end{align*}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Still dependent on the training data!\n",
    "\n",
    "<br>\n",
    "\n",
    "Classical network : $\\tiny p(\\boldsymbol{w},\\boldsymbol{\\alpha}) = \\delta(\\boldsymbol{w}-\\boldsymbol{w}^\\textrm{MLE},\\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)$\n",
    "\n",
    "Variational inference : $\\tiny p(\\boldsymbol{w},\\boldsymbol{\\alpha}) = \\mathcal{Q}(\\boldsymbol{w}|\\boldsymbol{v}^\\textrm{local MLE}, \\boldsymbol{\\alpha}^*, \\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1, n_\\textrm{train}]\\})$\n",
    "\n",
    "Bayesian neural networks : $\\tiny p(\\boldsymbol{w},\\boldsymbol{\\alpha}) =\\prod_i^{n_\\textrm{train}}\\mathcal{L}({\\bf t}^\\textrm{train}_i|{\\bf d}^\\textrm{train}_i,\\boldsymbol{w},\\boldsymbol{\\alpha})p(\\boldsymbol{w},\\boldsymbol{\\alpha})$\n",
    "\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/posterior_predictive_wrong_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# How can we use a neural network then?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Build it into the physical model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Method 1 : Model extension"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/NBM_square.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## We infer the neural network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# HMCLET"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### We want to infer the weights of the neural bias model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Hamiltonian Monte Carlo\n",
    "<div style=\"float:left;width:60%\">\n",
    "<sub>Introduce momentum ${\\small {\\bf p}\\leftarrow\\mathcal{N}({\\bf 0},{\\bf M})}$ and solve Hamilton's equations</sub>\n",
    "<br><br>\n",
    "$$\\begin{align*}\n",
    "{\\Tiny\\mathcal{H}(\\boldsymbol{\\theta}, {\\bf p}) }&{\\Tiny~= \\mathcal{V}(\\boldsymbol{\\theta}) + \\mathcal{K}({\\bf p})}\\\\\n",
    "&{\\Tiny~=\\mathcal{L}(\\boldsymbol{\\theta}|\\boldsymbol{\\delta})-\\log\\left[\\pi(\\boldsymbol{\\theta})\\right]+\\frac{1}{2}{\\bf p}^T{\\bf M}^{-1}{\\bf p}}\n",
    "\\end{align*}$$\n",
    "<sub>Accept samples according to probability</sub>\n",
    "\n",
    "$$\\begin{equation*}\n",
    "    {\\Tiny\\alpha = \\textrm{Min}\\left[\\exp\\left(\\Delta\\mathcal{H}\\right), 1\\right]}\n",
    "\\end{equation*}$$\n",
    "</div>\n",
    "<div style=\"float:right;width:35%\">\n",
    "    <br><br>\n",
    "    <img style=\"max-width:100%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/HMC_theta.svg\">\n",
    "    <br>\n",
    "</div>\n",
    "<div style=\"float:left;width:100%\">\n",
    "Evolve using ${\\Tiny\\dot{\\boldsymbol{\\theta}}= {\\bf M}^{-1}{\\bf p}}$ and ${\\Tiny\\dot{\\bf p}= -\\nabla\\mathcal{V}(\\boldsymbol{\\theta})}$\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### Acceptance is guaranteed if ODEs are perfectly solved"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "# Use leapfrog algorithm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### Leapfrog algorithm\n",
    "\n",
    "<img style=\"max-width:60%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/leapfrog.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### Acceptance criterion\n",
    "\n",
    "<img style=\"max-width:60%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/leapfrog_accept.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "# How does this work for neural networks?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "## Likelihood surface is extremely flat and highly degenerate\n",
    "<br>\n",
    "<img style=\"max-width:70%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/correlated_likelihood.svg\">\n",
    "\n",
    "Nearly impossible to know the mass matrix, ${\\bf M}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Use second order geometric information\n",
    "<img style=\"max-width:90%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/second_order.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### Quasi-Newtonian inverse Hessian\n",
    "\n",
    "$$\\begin{equation*}\n",
    "        {\\Tiny{\\bf B}^*=\\left(\\mathbb{I}-\\frac{\\boldsymbol{s}_i\\boldsymbol{y}_i^T}{\\boldsymbol{y}_i^T\\boldsymbol{s}_i}\\right){\\bf B}_i\\left(\\mathbb{I}-\\frac{\\boldsymbol{y}_i\\boldsymbol{s}_i^T}{\\boldsymbol{y}_i^T\\boldsymbol{s}_i}\\right)+\\frac{\\boldsymbol{s}_i\\boldsymbol{s}_i^T}{\\boldsymbol{s}_i^T\\boldsymbol{y}_i},}\n",
    "    \\end{equation*}\n",
    "$$\n",
    "<sub>with ${\\Tiny\\boldsymbol{s}_i=\\boldsymbol{\\theta}^*-\\boldsymbol{\\theta}_i}$ and ${\\Tiny\\boldsymbol{y}_i=\\nabla\\mathcal{L}(\\boldsymbol{\\theta}^*|\\boldsymbol{\\delta})-\\nabla\\mathcal{L}(\\boldsymbol{\\theta}_i|\\boldsymbol{\\delta})}$.</sub>\n",
    "\n",
    "#### Both $\\boldsymbol{s}$ and $\\boldsymbol{y}$ come for free with the leapfrog algorithm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "## We can now successfully traverse the likelihood surface\n",
    "\n",
    "The momenta and trajectories get rescaled by the Hessian providing a surface which is not as highly degenerate or flat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Neural physical engines\n",
    "\n",
    "Build networks using physical principles.\n",
    "\n",
    "- Reduces number of parameters\n",
    "\n",
    "- Increases computational efficiency\n",
    "\n",
    "- Decreases overfitting\n",
    "\n",
    "- Improves interpretability"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Convolutions for translational invariance\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/convolutional_network.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "### Architecture suited to the data\n",
    "\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/spherical_convolutional_network.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Use only causally relevant features\n",
    "<img style=\"max-width:90%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/receptive_field.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Use only informative features\n",
    "<br>\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/kernels.svg\">\n",
    "<br>\n",
    "<sub><a href=\"https://github.com/tomcharnock/multipole_kernels\">github:multipole_kernels</a></sub>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Halo mass distribution function\n",
    "<img style=\"width:800px;max-height:100%;display:block;margin:auto;float:none!important;\" src=\"../figures/hmdf.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Neural density estimators"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Halo mass distribution function is a smooth function of mass given a density environment"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### Use a mixture density network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<img style=\"max-width:90%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/MDN.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Our neural density estimator\n",
    "$$\\begin{align*}\n",
    "        {\\tiny n(M|\\delta) =}&{\\tiny \\sum_i^N\\alpha(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\alpha}})\\mathcal{N}\\left(\\mu(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\mu}}), \\sigma(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\sigma}})|M\\right),}\\\\\n",
    "        {\\tiny =}&{\\tiny \\sum_i^N\\frac{\\alpha(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\alpha}})}{\\sqrt{2\\pi\\left(\\sigma(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\sigma}})\\right)^2}}\\exp\\left[-\\frac{\\left(\\log(M) - \\mu(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\mu}})\\right)^2}{2\\left(\\sigma(\\boldsymbol{\\psi}, \\boldsymbol{\\theta}_i^{\\boldsymbol{\\sigma}})\\right)^2}\\right],}\\end{align*}\n",
    "$$\n",
    "<div style=\"float:left;width:40%\">\n",
    "    <img style=\"max-width:100%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/MOG.svg\">\n",
    "</div>\n",
    "<div style=\"float:right;width:59%\">\n",
    "    $$\n",
    "    \\begin{align*}\n",
    "{\\tiny\\alpha_i} & {\\tiny=\\text{softplus}(w_{i}^\\alpha\\boldsymbol{\\psi}+b^\\alpha_i),}\\\\\n",
    "{\\tiny\\mu_i }&{\\tiny = \\left\\{\\begin{array}{ll}\n",
    "            w_{i}^\\mu\\boldsymbol{\\psi}+b^\\mu_i&i=0\\\\\n",
    "            \\textrm{Max}\\left[0,~ w_{i}^\\mu\\boldsymbol{\\psi}+b^\\mu_i\\right]+\\mu_{i-1}&i>0\\\\\n",
    "            \\end{array}\\right.,}\\\\\n",
    "{\\tiny\\sigma_i} &{\\tiny = \\text{softplus}(w_{i}^\\sigma\\boldsymbol{\\psi}+b^\\sigma_i)\\;,}\n",
    "    \\end{align*}\n",
    "    $$\n",
    "</div>\n",
    "<div style=\"float:left;width:100%\">\n",
    "<sub>2 Gaussians with<br> ${\\Tiny\\boldsymbol{b}^\\alpha \\to \\boldsymbol{b}^\\alpha +\\log(10^{-3})}$, ${\\Tiny b_0^\\mu \\to b_0^\\mu + \\log\\left(2\\times10^{12}\\right)}$ and ${\\Tiny\\boldsymbol{b}^\\sigma\\to \\boldsymbol{b}^\\alpha + \\log(10^3)}$.</sub>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Likelihood"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "$$\\begin{align*}\n",
    "        {\\Tiny\\mathcal{L}  =}&{\\Tiny \\sum_{j\\in\\textrm{catalogue}}\\log\\left[\\sum_i^N\\frac{\\alpha_{i,j}}{\\sqrt{2\\pi\\sigma_{i,j}^2}}\\exp\\left[-\\frac{\\left(\\log(M_j) - \\mu_{i,j}\\right)^2}{2\\sigma_{i,j}^2}\\right]\\right]}\\\\\n",
    "        &{\\Tiny - V\\sum_{j\\in\\textrm{voxels},i=1}^N\\frac{\\alpha_{i,j}}{2}\\exp\\left[\\frac{\\sigma_{i,j}^2}{2}\\right]\\textrm{erfc}\\left[\\frac{\\log\\left(M_\\textrm{th}\\right) - \\mu_{i,j} - \\sigma_{i,j}^2}{\\sqrt{2\\sigma_{i,j}^2}}\\right].}\n",
    "    \\end{align*}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "This is Poissonian.<br>\n",
    "But on the NPE field, so it is non-local"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "# Actual results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/NBM_square.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Sample the power spectrum\n",
    "<br>\n",
    "<img style=\"width:600px;max-width:200%;max-height:200%;display:block;margin:auto;float:none!important;\" src=\"../figures/Pk.svg\">\n",
    "✓ Power spectra remain smooth and close to prior"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Sample the weights of the neural bias model\n",
    "<br>\n",
    "<img style=\"width:900px;max-width:100%;max-height:100%;display:block;margin:auto;float:none!important;\" src=\"../figures/weight_trace.svg\">\n",
    "\n",
    "✓ Weight values are properly sampled after burn in<br>\n",
    "✓ NPE acts as a contrast enhancer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### See the effects of the neural physical engine\n",
    "<br>\n",
    "<img style=\"width:500px;max-height:100%;display:block;margin:auto;float:none!important;\" src=\"../figures/3D_projections.svg\">\n",
    "\n",
    "✓ Non-local information is used to improve fit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# And what does the halo mass distribution function look like?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Halo mass distribution function from neural bias model\n",
    "<br>\n",
    "<img style=\"width:800px;max-height:100%;display:block;margin:auto;float:none!important;\" src=\"../figures/hmdf.svg\">\n",
    "✓ Fits data!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Method 2 : Likelihood-free inference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:100%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/physical_model_nn.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Likelihood-free inference using machine learning"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Approximate Bayesian computation\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/ABC.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Why even introduce the neural network?\n",
    "<br>\n",
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/ABC_2D.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Inadequate sampling\n",
    "\n",
    "Impossibly large numbers of simulations become necessary to correctly sample the posterior\n",
    "\n",
    "<img style=\"max-width:60%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/bad_posterior.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# We need to do some compression"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Any pretrained neural network *could* be used"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "#### Is there a well motivated choice?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "<img style=\"max-height:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/IMNN.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Information maximising neural networks\n",
    "<br>\n",
    "<div style=\"float:left;width:60%\">\n",
    "    Which function $\\mathscr{f}: \\mathbb{R}^{\\bf d}\\to \\mathbb{R}^\\boldsymbol{\\theta}$ maximises the Fisher information of the summaries ${\\bf x}$ from that function?\n",
    "    <br>\n",
    "    <br>\n",
    "    <br>\n",
    "    $$\\mathcal{L}({\\bf d}|\\boldsymbol{\\theta})\\to\\mathcal{L}({\\bf x}|\\boldsymbol{\\theta}, {\\bf d})$$\n",
    "</div>\n",
    "<div style=\"float:left;width:40%\">\n",
    "    <img style=\"max-width:8\n",
    "                90%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"figures/F.gif\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Fisher information of the network summaries\n",
    "\n",
    "#### Simulations $\\{{\\bf d}_i|i\\in[1, n_{\\bf d}]\\}$ at a single parameter value $\\boldsymbol{\\theta}^*$\n",
    "\n",
    "#### Seed matched simulations $\\{{\\bf d}_i^{\\pm}|i\\in[1, n_{\\bf p}]\\}$ at perturbed fiducial paremeters $\\Delta\\boldsymbol{\\theta}^\\pm=\\boldsymbol{\\theta}\\pm\\boldsymbol{\\delta}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Calculate the covariance\n",
    "<img style=\"max-width:80%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/covariance.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Calculate the derivative of the mean of the summaries with respect to the parameters\n",
    "<img style=\"max-width:80%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/dmdt.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Calculate the Fisher information\n",
    "\n",
    "$${\\bf F}_{\\alpha\\beta}=\\frac{\\partial\\mu_\\mathscr{f}}{\\partial\\theta_\\alpha}^T{\\bf C}^{-1}_\\mathscr{f}\\frac{\\partial\\mu_\\mathscr{f}}{\\partial\\theta_\\beta}$$\n",
    "\n",
    "This Gaussian form forces the summaries to be Gaussianised"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Optimise the tunable parameters of the network such that $\\ln|{\\bf F}_{\\alpha\\beta}|$ is maximised!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Once converged the network compresses *and* Gaussianises the data *without* losing information*\n",
    "<br><br><br><br>\n",
    "*in the optimal case..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## And we get free maximum likelihood estimates...\n",
    "\n",
    "$$\\boldsymbol{\\theta}^\\textsf{MLE}_\\alpha=\\boldsymbol{\\theta}_\\alpha^*+{\\bf F}_{\\alpha\\beta}^{-1}{\\bf C}_\\mathscr{f}^{-1}\\frac{\\partial\\mu_\\mathscr{f}}{\\partial\\theta_\\beta}({\\bf x}-\\mu_\\mathscr{f})$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## And we can get free approximations of the posterior\n",
    "\n",
    "$$\\textsf{Cov}[\\boldsymbol{\\theta}_\\alpha^\\textsf{MLE},\\boldsymbol{\\theta}_\\beta^\\textsf{MLE}] \\ge {\\bf F}_{\\alpha\\beta}^{-1}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Or do likelihood-free inference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### We pass our observed data through the network <br>(put it to the side)\n",
    "<img style=\"max-width:100%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/xobs.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Draw simulations (cleverly?) from the prior model parameters, $\\mathcal{P}(\\boldsymbol{\\theta})$ and pass them through the network\n",
    "<img style=\"max-width:100%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/xsims.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Measure the difference between the summarised simulations and the observed summary\n",
    "<br>\n",
    "<img style=\"max-width:60%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/rho.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "<b>Compare distance between observed summaries and simulation summaries and select results within $\\epsilon$</b><br><br>\n",
    "<img style=\"max-width:70%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/ABC_IMNN.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Conclusions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### Neural networks are not to be trusted\n",
    "\n",
    "### They can make trusty companions - when the correct framework is introduced\n",
    "\n",
    "### Using statistics we can build them into the forward model to give us lossless summaries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Take home message"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Stop doing machine learning, think, then start doing machine learning again!"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Diaporama",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "rise": {
   "leap_motion": {
    "naturalSwipe": true,
    "pointerColor": "#d80000",
    "pointerOpacity": 0.5
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
